package com.aruba.girlanime;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.LayoutRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aruba.girlanime.delegate.GirlAnimeDelegate;
import com.aruba.girlanime.delegate.HanabiAnimeDelegate;
import com.aruba.girlanime.delegate.HoushAnimeDelegate;
import com.aruba.girlanime.delegate.IAnimeDelegate;
import com.aruba.girlanime.delegate.ItemAnimeDelegate;
import com.aruba.girlanime.delegate.PhotoAnimeDelegate;
import com.aruba.girlanime.delegate.RobotAnimeDelegate;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.rl_main)
    RelativeLayout rl_main;
    @BindView(R.id.ll_girl)
    LinearLayout iv_girl;
    @BindView(R.id.iv_dialog_right)
    ImageView iv_dialog_right;
    @BindView(R.id.iv_dialog_left)
    ImageView iv_dialog_left;
    @BindView(R.id.iv_man)
    ImageView iv_man;
    IAnimeDelegate girlAnimeDelegate = new GirlAnimeDelegate();

    @BindView(R.id.iv_house_one)
    ImageView iv_house_one;
    @BindView(R.id.iv_house_two)
    ImageView iv_house_two;
    @BindView(R.id.iv_house_three)
    ImageView iv_house_three;
    @BindView(R.id.iv_house_four)
    ImageView iv_house_four;
    IAnimeDelegate houseAnimeDelegate = new HoushAnimeDelegate();

    @BindView(R.id.iv_green)
    ImageView iv_green;
    @BindView(R.id.iv_arrow1)
    ImageView iv_arrow1;
    @BindView(R.id.iv_arrow2)
    ImageView iv_arrow2;
    @BindView(R.id.iv_yellow)
    ImageView iv_yellow;
    @BindView(R.id.iv_star)
    ImageView iv_star;
    IAnimeDelegate itemAnimeDelegate = new ItemAnimeDelegate();

    @BindView(R.id.iv_come)
    ImageView iv_come;
    @BindView(R.id.iv_robot)
    ImageView iv_robot;
    @BindView(R.id.rl_robot)
    RelativeLayout rl_robot;
    IAnimeDelegate robotAnimeDelegate = new RobotAnimeDelegate();


    @BindView(R.id.tv_left)
    TextView tv_left;
    @BindView(R.id.tv_right)
    TextView tv_right;
    IAnimeDelegate photoAnimeDelegate = new PhotoAnimeDelegate();

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
    }

    @BindView(R.id.iv_test)
    ImageView iv_test;

    @BindView(R.id.rl_hanabi)
    RelativeLayout rl_hanabi;
    @BindView(R.id.iv_hanabi1)
    ImageView iv_hanabi1;
    @BindView(R.id.iv_hanabi2)
    ImageView iv_hanabi2;
    @BindView(R.id.iv_hanabi3)
    ImageView iv_hanabi3;
    @BindView(R.id.iv_hanabi4)
    ImageView iv_hanabi4;
    @BindView(R.id.iv_hanabi5)
    ImageView iv_hanabi5;
    @BindView(R.id.iv_hanabi6)
    ImageView iv_hanabi6;
    IAnimeDelegate hanabiAnimeDelegate = new HanabiAnimeDelegate();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏
        setContentView(R.layout.activity_main);


        girlAnimeDelegate.init(rl_main, iv_girl, iv_dialog_right, iv_dialog_left, iv_man);

        houseAnimeDelegate.init(iv_house_one, iv_house_two, iv_house_three, iv_house_four);

        itemAnimeDelegate.init(iv_green, iv_arrow1, iv_arrow2, iv_yellow, iv_star);

        BitmapDrawable bitmapDrawable1 = (BitmapDrawable) getResources().getDrawable(R.mipmap.ico_photo_bg);
        BitmapDrawable bitmapDrawable2 = (BitmapDrawable) getResources().getDrawable(R.mipmap.ico_photo_bg);
        BitmapDrawable bitmapDrawable3 = (BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher);

        iv_test.setImageBitmap(BitmapUtils.mergebitmap(bitmapDrawable1.getBitmap(), bitmapDrawable2.getBitmap(), bitmapDrawable3.getBitmap()));
//
//        QRDialog qrDialog = new QRDialog(this);
//        qrDialog.show();

        robotAnimeDelegate.init(iv_come, iv_robot, rl_robot);

        photoAnimeDelegate.init(tv_left, tv_right);

        hanabiAnimeDelegate.init(rl_hanabi, iv_hanabi1, iv_hanabi2, iv_hanabi3, iv_hanabi4, iv_hanabi5, iv_hanabi6);
    }

    private int count;
    private Runnable runnable;

    public void click(View view) {
        count++;
        if (count % 2 == 0) {
            girlAnimeDelegate.reset();
        } else {
            girlAnimeDelegate.startAnime();
        }

        robotAnimeDelegate.startAnime();
        photoAnimeDelegate.startAnime();

        if (runnable == null) {
            runnable = new Runnable() {
                @Override
                public void run() {
                    hanabiAnimeDelegate.startAnime();
                    new Handler().postDelayed(runnable, 4000);
                }
            };
            new Handler().post(runnable);
            view.setVisibility(View.GONE);
        }
    }
}
